{include file="public/header"}
    <title>会员列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
</head>
<body>
<div class="wap-container">
    <nav class="breadcrumb" style="background-color:#fff;padding: 0 24px">
        <a class="btn btn-success radius f-r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <article class="Hui-admin-content clearfix">
        <div class="panel mt-20">
            <div class="panel-body">
                <div class="clearfix">
						<!--<span class="f-l">
							<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
							<a href="javascript:;" onclick="member_add('添加用户','member-add.html','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加用户</a>
						</span>-->
                    <span class="f-r">共有数据：<strong>{$total}</strong> 条</span>
                </div>
                <div class="clearfix mt-20">
                    <table class="table table-border table-bordered table-hover table-bg table-sort">
                        <thead>
                        <tr class="text-c">
                            <th width="25"><input type="checkbox"  name="" value=""></th>
                            <th width="80">ID</th>
                            <th width="100">昵称</th>
                            <!--<th width="40">手机号</th>-->
                            <th width="90">手机</th>
                            <th width="70">是否在线</th>
                            <th width="100">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach $users as $k=>$v}
                        <tr class="text-c">
                            <td><input type="checkbox" value="{$v.id}" name="id"></td>
                            <td>{$v.id}</td>
                            <td>{$v.nick_name}</td>
                            <!--<td><u style="cursor:pointer" class="text-primary" onclick="member_show('张三','member-show.html','10001')">1111</u></td>-->
                            <td class="text-l">{$v.mobile}</td>
                            <td class="td-status">
                                {if condition="in_array($v.id,$lineUser)"}
                                <span class="label label-success radius">在线</span>
                                {else/}
                                <span class="label label-danger radius">离线</span>
                                {/if}
                            </td>
                            <td class="td-manage">
                                <span id="{$v.id}"></span>
                                {if condition="$v.id eq $sess_user_id"}{else/}
                                <a title="在线聊天" href="javascript:;" onclick="admin_edit('在线聊天','/chat/user/chatDetail/id/{$v.id}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                                {/if}
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </article>
    <input type="hidden" id="current_user" value="{$currentUser}">
</div>
{include file="public/footer"}
<!--请在下方写此页面业务相关的脚本-->
<!--<script src="__CHAT__/jquery.min.js"></script>-->
<script type="text/javascript" src="__CHAT__/admin_template/lib/datatables/1.10.15/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__CHAT__/admin_template/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="__CHAT__/admin_template/static/business/js/main.js"></script>
<script type="text/javascript">
    $(function(){
        runDatetimePicker();
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
<script>
    var current_user = eval('(' + $("#current_user").val() + ')');
    var ws = new WebSocket("ws://127.0.0.1:8282"); //实例化

    //打开
    ws.onopen = function(){
        checkUserLine();
        bindUid(); //绑定用户id
    };

    //监听返回的消息
    ws.onmessage = function(e){
        var data = eval('('+e.data+')');
        // console.log(data);
        //
        switch (data.type) {
            case 'userCheckUserLine':
                postCheckUserLine(data.data);
                return;
            case 'OnLine':
                onLine(data);
                return;
            case 'outLine':
                // checkUserLine();//查询出来所有在线的用户
                sendOutLine(data);
                return;
            case 'outLineMsg':
                outLineMsg(data);
                checkUserLine();
                // console.log(data);
                return;

        }
    };

    //查询在线的用户
    function checkUserLine(){
        var send_message = '{"type":"userCheckUserLine"}';
        ws.send(send_message);
    }
    function postCheckUserLine(data){
        // console.log(data);
        // $.post("{:url('chatList')}",data,function(data){
        //     console.log(data);
        // });
    }

    //上线提示
    function onLine(data){
        var id = data.user_id;
        $("#"+id).parents("tr").find(".td-status").html('<span class="label label-success radius">在线</span>');
        layer.msg(data.nick_name+data.data, {icon:6,time:1000});
        // location.reload();
    }

    //(发送离线 至服务端)
    function sendOutLine(data){
        // console.log(data);
        var send_message = '{"type":"'+data.type+'","client_id":"'+data.client_id+'"}';
        ws.send(send_message);
    }
    //离线提示
    function outLineMsg(data){
        var id = data.user_id;
        $("#"+id).parents("tr").find(".td-status").html('<span class="label label-danger radius">离线</span>');
    }

    //绑定uid
    function bindUid(){
        var send_message = '{"type":"userChatBindUid","user_id":"' + current_user.id + '","nick_name":"' + current_user.nick_name + '"}';
        ws.send(send_message);
    }
    /*管理员-编辑*/
    function admin_edit(title,url){
        var index = layer.open({
            type: 2,
            title: title,
            content: url,
        });
        layer.full(index);
    }
</script>
</html>
